import { Table, Pagination } from 'antd';
import React, { useState } from 'react'


const columns = [
  {
    title: '序号',
    dataIndex: 'index',
    key: 'index',
    width: 60,
    align: 'center',
    render: (text, record, index) => {
      return text
    },
  },
  {
    title: '学期',
    dataIndex: 'fd_semester',
    key: 'fd_semester',
    width: 80,
    align: 'center',
    render: (text, record, index) => {
      if(text === 1) return "大一上"
      if(text === 2) return "大一下"
      if(text === 3) return "大二下"
      if(text === 4) return "大二下"
      if(text === 5) return "大三下"
      if(text === 6) return "大三下"
      if(text === 7) return "大四下"
      if(text === 8) return "大四下"
    },
  },
  {
    title: '课程名',
    dataIndex: 'fd_curriculumName',
    key: 'fd_curriculumName',
    width: 120,
    align: 'center',
  },
  {
    title: '课程号',
    dataIndex: 'fd_curriculumNum',
    key: 'fd_curriculumNum',
    width: 120,
    align: 'center',
  },
  {
    title: '专业',
    dataIndex: 'fd_professionalName',
    key: 'fd_professionalName',
    width: 180,
    align: 'center',
  },
  {
    title: '类别',
    dataIndex: 'fd_type',
    key: 'fd_type',
    width: 120,
    align: 'center',
    render: (text, record, index) => {
      if(text === 1) return "必修"
      if(text === 2) return "选修"
    },
  },
  {
    title: '学分',
    dataIndex: 'fd_credit',
    key: 'fd_credit',
    width: 60,
    align: 'center',
  },
  {
    title: '考核方式',
    dataIndex: 'fd_assessmentMethod',
    key: 'fd_assessmentMethod',
    width: 120,
    align: 'center',
    render: (text, record, index) => {
      if(text === 1) return "开卷考试"
      if(text === 2) return "闭卷考试"
      if(text === 3) return "考察"
    },
  },
  {
    title: '学时',
    dataIndex: 'fd_creditHours',
    key: 'fd_creditHours',
    width: 60,
    align: 'center',
  },
  {
    title: '备注',
    dataIndex: 'fd_remarks',
    key: 'fd_remarks',
    width: 120,
    align: 'center',
  },
];

export default function TrainingPlanList({curriculum}) {

  const [currentPage, setCurrentPage] = useState(1);
  const pageSize = 11;
  const total = curriculum?.length;

  const onPageChange = (page, pageSize) => {
    setCurrentPage(page);
  };

  const start = (currentPage - 1) * pageSize;
  const end = start + pageSize;
  const currentData = curriculum?.slice(start, end).map((item, index) => {
    const curriculum = {...item,index:index + 1 + start}
    return curriculum
  }
  );

  return (
    <div>
      <>
        <Table
          bordered
          columns={columns}
          dataSource={currentData}
          pagination={false}
          size="small"
          rowKey={"index"}
          scroll={{ x: 'max-content' }}
        />
        <Pagination
          current={currentPage}
          pageSize={pageSize}
          total={total}
          onChange={onPageChange}
          showSizeChanger={false}
          style={{ marginTop: '16px', textAlign: "right" }}
        />
      </>
    </div>
  )
}
